package com.gcmm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.gcmm.utils.FileUtils;

import java.util.List;

@Controller
@RequestMapping("/file")
public class FileController {

        @GetMapping
        public String index(String path, Model model) {
            if (path==null || path.isEmpty()){
                return "hello";
            }
            List<String> fileNames = FileUtils.getAllFileNames(path);
            String names = String.join(",", fileNames);

            model.addAttribute("fileNames", fileNames);
            model.addAttribute("path",path);
            System.out.println("hello");
            return "hello";
        }
        @GetMapping("/copy-to-file")
    public String copyToFile(String path,String outPath,Model model){
            if (path==null || path.isEmpty()||outPath==null || outPath.isEmpty()){
                return "copyToFile";
            }
            FileUtils.copyAllContentToFile(path,outPath);
            model.addAttribute("path",path);
            model.addAttribute("outPath",outPath);
            return "copyToFile";
        }

}
